package org.example.freeswitchdemo.controller;


import org.example.freeswitchdemo.listener.FreeswitchHealthChecker;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class FreeswitchHealthController {

    private final FreeswitchHealthChecker healthChecker;

    public FreeswitchHealthController(FreeswitchHealthChecker healthChecker) {
        this.healthChecker = healthChecker;
    }

    @GetMapping("/health/freeswitch")
    public Map<String, Object> checkHealth() {
        Map<String, Object> result = new HashMap<>();
        boolean alive = healthChecker.isFreeswitchAlive();
        result.put("freeswitchAlive", alive);
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }
}

